#!/bin/bash

# 简单安装 APScheduler 依赖脚本

# 确保在正确的目录执行
cd /usr/local/nginx/html/prod/dz || {
    echo "无法切换到应用目录，脚本退出"
    exit 1
}

# 激活虚拟环境
echo "激活虚拟环境..."
source /usr/local/nginx/html/prod/dz/venv/bin/activate
if [[ -z $VIRTUAL_ENV ]]; then
    echo "虚拟环境激活失败，请检查虚拟环境路径是否正确"
    exit 1
fi

echo "虚拟环境激活成功: $VIRTUAL_ENV"

# 安装 APScheduler
echo "安装 APScheduler..."
pip install APScheduler~=3.10.4
if [[ $? -ne 0 ]]; then
    echo "APScheduler 安装失败，尝试使用国内源..."
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple APScheduler~=3.10.4
    if [[ $? -ne 0 ]]; then
        echo "APScheduler 安装失败，请检查网络连接"
        exit 1
    fi
fi

echo "APScheduler 安装成功"

# 验证安装
echo "验证 APScheduler 安装..."
python -c "import apscheduler; print('APScheduler 版本:', apscheduler.__version__)" || {
    echo "APScheduler 验证失败"
    exit 1
}

echo "APScheduler 验证成功，可以启动应用了"